!function(window,document,$,undefined) {
	var getUrl = getWashUrl(),
		longitude = localStorage.getItem('userLng'),
		latitude = localStorage.getItem('userLng'),
		map;
	$(function() {
		var init = function() {
			bindEvt();
			// BdMap();
			getNearbyLaundryList();
		}
		var bindEvt = function() {
			$('.close').on('tap',function() {$('#ldry_info').hide();return false;});
			$('#ldry_info').on('tap',onLdryInfoTap);
			$('.goback').on('tap',function() {history.go(-1)});
		}
			
		var onLdryInfoTap =function() { //跳转至详情页同时传递商家id和当前距离
			// var laundryId = $(this).attr('data-id'),
				// distance = $(this).attr('data-distance');
			// localStorage.setItem('laundryId',laundryId);
			// window.location.href = 'laundrydetail.html?laundryId='+laundryId+'&distance='+distance+'';
			window.location.href = 'laundrydetail.html';

		}
		function BdMap() {
			map = new BMap.Map("ldry");
			var point = new BMap.Point(116.40387397,39.91488908);//换成变量，传当前位置值
			map.centerAndZoom(point,11);
			var geolocation = new BMap.Geolocation();
			geolocation.getCurrentPosition(function(r){
				if(this.getStatus() == BMAP_STATUS_SUCCESS){
					// var mk = new BMap.Marker(r.point);
					// map.addOverlay(mk);
					// mk.enableDragging(true);  
					// map.panTo(r.point);
					// console.log(r.point)
					// alert('您的位置：'+r.point.lng+','+r.point.lat);
				}
				else {
					alert('failed'+this.getStatus());
				}        
			},{enableHighAccuracy: true})
		}

			

		function getNearbyLaundryList() { //店铺列表接口调用
			var url = getUrl+'/common/laundry/getNearbyLaundryList.api',
				signDate = {
					longitude:116.479077,//换成变量
					latitude:39.916671,//换成变量
					type:4,
					ssid:getTime(),
					distance:2000000000,//最多不超过30亿米哈哈
					pageNumber:1
				};
				$.extend(signDate,{sign:getObjectString(signDate)});
			$.ajax({
				method:'GET',
				url:url,
				data:signDate,
				dataType:'json',
				success:onLdryListSuccess
			})
		}
		var onLdryListSuccess = function(response) {
			console.log(response);
			var data = response.data,
				laundry,
				pointArr = new Array();
			var map = new BMap.Map("ldry");
			var point = new BMap.Point(116.40387397,39.91488908);
			map.centerAndZoom(point,15);
			$.each(data,function(i,obj) {
				var oPoint,oMarker;
				laundry = obj.laundry;
				pointArr[i] = new BMap.Point(laundry.longitude,laundry.latitude);
				oPoint = new BMap.Point(laundry.longitude,laundry.latitude);
				oMarker = new BMap.Marker(oPoint);
				map.addOverlay(oMarker);
				oMarker.addEventListener("click",attribute);
				map.setViewport(pointArr);
			});
			function attribute(e) {
				var p = e.target,
				    lng =  p.getPosition().lng,
				    lat =  p.getPosition().lat,
				    tmpLaundry = {},
				    tmpObj = {},
				    tmpArr = [];
				$.each(data,function(i,obj) {
					// console.log(obj.laundry.longitude)
					if(obj.laundry.longitude==lng&&obj.laundry.latitude==lat) {
						tmpLaundry = obj.laundry;
						tmpObj = data[i];
						$('#ldry_info').attr('data-id',''+tmpLaundry.laundryId+'');
					}
				});
				$('#ldry_info').css('display','block');
				$('.ldy_distance span').html(tmpObj.distance);
				$('address').html(tmpLaundry.address);
				if(tmpLaundry.laundryactivityinfos) {
					$('.ldry_botm').show();
				}else {
					$('.ldry_botm').hide();
				}
				if(laundry.businessStatus=='1'||(!laundry.businessStatus)) {
					$('.ldy_name').html(tmpLaundry.name+'(打烊了)');
				}else {
					$('.ldy_name').html(tmpLaundry.name);
				}
				lightStar(tmpLaundry.star);
			}	
		}
		function lightStar(n) { //点亮星星的个数方法(传商家亮星个数)
			var wrapper = $('.wrapper'),
				stars = wrapper.find('img')
				i,j,len = stars.length-n;
			for(i=0;i<n;i++) {
				stars[i].src = '../images/hl_star.png';
			};
			if(n<stars.length) {
				for(j=n;j<stars.length;j++) {
					stars[j].src = '../images/h_star.png'
				};
			};
		}	

		init();
	})
}(window,document,Zepto)